#include <iostream>
#include <ostream>
#include <string>

using namespace std;

/*
 尝试使用全局函数实现+= == !=
 */

class Complex {
	public:
		Complex() : m_real(0.0), m_img(0.0) {}
		Complex(float real, float img) : m_real(real), m_img(img) {}
		void show() {cout << m_real << "+" << m_img << "i" << endl;}
		// 重载运算符
		Complex operator+(const Complex &c);
		friend Complex operator-(const Complex &a, const Complex &b);
		friend Complex operator+=(Complex &a, const Complex &b);
		friend bool operator!=(const Complex &a, const Complex &b);
		friend bool operator==(const Complex &a, const Complex &b);
		friend ostream &operator << (ostream &out, const Complex &c);
		friend istream &operator>> (istream &in, Complex &c);

	private:
		float m_real;
		float m_img;
};

Complex Complex::operator+(const Complex &c)
{
	Complex res;

	res.m_real = this->m_real + c.m_real;
	res.m_img = this->m_img + c.m_img;

	return res;
}

// 全局函数 声明为类的友元函数
Complex operator-(const Complex &a, const Complex &b)
{
	Complex res;
	res.m_real = a.m_real - b.m_real;
	res.m_img = a.m_img - b.m_img;
	return res;
}

// c = (a += b);

Complex operator+=(Complex &a, const Complex &b)
{
	a.m_real += b.m_real;
	a.m_img += b.m_img;

	return a;
}

bool operator==(const Complex &a, const Complex &b)
{
	return a.m_real == b.m_real && a.m_img == b.m_img;
}

bool operator!=(const Complex &a, const Complex &b)
{
	return !(a.m_real == b.m_real && a.m_img == b.m_img);
}

ostream &operator << (ostream &out, const Complex &c)
{
	out << c.m_real << "+" << c.m_img << "i";

	return out;
}

istream &operator>> (istream &in, Complex &c)
{
	in >> c.m_real >> c.m_img;
	return in;
}

int main(void)
{
	Complex c1(1.2, 7.2);
	Complex c2(2.3, 5.6);
	Complex c3;
	string s1, s2, s3;
	bool ret;

	cin >> c3;
	cout << c3 << endl;

#if 0
	s2 = "hello";
	s3 = "world";
	// s2.operator+(s3)
	s1 = s2 + s3;
	cout << s1 << endl;
	// c1.operator+(c2)
	c3 = c1 + c2;

	c1.show();
	c2.show();
	c3.show();

	c3 = c1 - c2;
	c3.show();

	c1 += c2;
	c1.show();
	
	// operator<< (cout, c1)
	cout << c1 << endl;

	ret = c1 == c2;
	cout << ret << endl;
	ret = c1 != c2;
	cout << ret << endl;
#endif

	return 0;
}

